package concurrence;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by gzhd on 2017/11/21.
 */
public class ThreadPoolDemo {
    public static class MyTask implements Runnable {

        @Override
        public void run() {
            System.out.println(System.currentTimeMillis() + " Thread ID:" + Thread.currentThread().getId()+"start");
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
            }
            System.out.println(System.currentTimeMillis() + " Thread ID:" + Thread.currentThread().getId()+"end");

        }
    }

    public static void main(String[] args) {
//        MyTask myTask = new MyTask();
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 2; i++) {
            MyTask myTask = new MyTask();
            executorService.submit(myTask);
        }
        System.out.println("all end");
    }
}
